import RoleApi from "@/api/acl/role";
const state = {
  roleList: [],
};
const mutations = {
  GETROLES(state, data) {
    state.roleList = data;
  },
};
const actions = {
  //获取角色列表
  async getRoles({ commit }, data) {
    const { page, limit, searchParams } = data;
    const result = await RoleApi.getPageList(page, limit, searchParams);
    if (result.code == 20000) {
      let arr = result.data.items.map((item) => {
        item.edit = false; // 用于标识是否显示编辑输入框的属性
        item.originRoleName = item.roleName; // 缓存角色名称,用于取消
        return item;
      });
      result.data.items = arr;
      commit("GETROLES", result.data);
      return "ok";
    } else {
      return Promise.reject(new Error(result.message));
    }
  },
};
const getters = {
  roleItems() {
    return (state.roleList || {}).items || [];
  },
  roleTotal() {
    return state.roleList.total;
  },
};

export default {
  state,
  mutations,
  actions,
  getters,
};
